unit uLBMPPackage;

interface

uses
  SysUtils, Classes, uDZPersistent, uGxtMobileLocateNative;

type
  TLBMPRequestType = (lbmpGetAreaCode, lbmpGetCoord, lbmpRegister,
    lbmpUnRegister, lbmpGetLBSState, lbmpConfirmRegister);

  TLBMPLocateType = (lbmpCityLocate, lbmpCoordLocate);

  TLBMPPackageHeader = packed record
    headerLen: Word;
    format: Word;
    _type: Word;
    option: Word;
    packageLen: Integer;
  end;
  PLBMPPackageHeader = ^TLBMPPackageHeader;

  TLBMPPhoneActionResult = class(TPersistent)
  private
    fPhone: AnsiString;
    fErrorCode: Integer;
    fErrorMsg: WideString;
  published
    property Phone: AnsiString read fPhone write fPhone;
    property ErrorCode: Integer read fErrorCode write fErrorCode;
    property ErrorMsg: WideString read fErrorMsg write fErrorMsg;
  end;

  TLBMPServiceStatusResult = class(TLBMPPhoneActionResult)
  private
    fServiceStatus: TLbmpSvcState;
  published
    property ServiceStatus: TLbmpSvcState
      read fServiceStatus write fServiceStatus;
  end;

  TLBMPAreaCodeResult = class(TLBMPPhoneActionResult)
  private
    fAreaCode: Integer;
  published
    property AreaCode: Integer read fAreaCode write fAreaCode;
  end;

  TLBMPCoordResult = class(TLBMPPhoneActionResult)
  private
    fLatitude: AnsiString;
    fLongitude: AnsiString;
  published
    property Longitude: AnsiString read fLongitude write fLongitude;
    property Latitude: AnsiString read fLatitude write fLatitude;
  end;

  TLBMPRequestPackage = class(TPersistent)
  public
    class function GetType: TLBMPRequestType; virtual; abstract;
  end;
  TLBMPRequestPackageClass = class of TLBMPRequestPackage;

  TLBMPResponsePackage = class(TPersistent)
  private
    fErrorCode: Integer;
    fErrorMessage: WideString;
  public
    class function GetType: TLBMPRequestType; virtual; abstract;
  published
    property ErrorCode: Integer read fErrorCode write fErrorCode;
    property ErrorMessage: WideString read fErrorMessage write fErrorMessage;
  end;
  TLBMPResponsePackageClass = class of TLBMPResponsePackage;

  TLBMPREQMobilePhone = class(TLBMPRequestPackage)
  private
    fPhones: TStrings;
    procedure SetPhones(const Value: TStrings);
  public
    constructor Create(); override;
    destructor Destroy(); override;
  published
    property Phones: TStrings read fPhones write SetPhones;   
  end;
  
  TLBMPREQGetAreaCode = class(TLBMPREQMobilePhone)
  public
    class function GetType: TLBMPRequestType; override;
  end;

  TLBMPREQGetCoord = class(TLBMPREQMobilePhone)
  public
    class function GetType: TLBMPRequestType; override;
  end;

  TLBMPREQRegister = class(TLBMPREQMobilePhone)
  public
    class function GetType: TLBMPRequestType; override;  
  end;

  TLBMPREQUnRegister = class(TLBMPREQMobilePhone)
  public
    class function GetType: TLBMPRequestType; override;  
  end;

  TLBMPREQGetServiceStatus = class(TLBMPREQMobilePhone)
  public
    class function GetType: TLBMPRequestType; override;  
  end;

  TLBMPREQConfirmRegister = class(TLBMPREQMobilePhone)
  public
    class function GetType: TLBMPRequestType; override;  
  end;

  TLBMPRESGetAreaCode = class(TLBMPResponsePackage)
  private
    fResultList: TPersistentList;
    procedure SetResultList(const Value: TPersistentList);
  public
    constructor Create(); override;
    destructor Destroy(); override;
    class function GetType: TLBMPRequestType; override;
  published
    property ResultList: TPersistentList read fResultList write SetResultList;    
  end;

  TLBMPRESGetCoord = class(TLBMPResponsePackage)
  private
    fResultList: TPersistentList;
    procedure SetResultList(const Value: TPersistentList);
  public
    constructor Create(); override;
    destructor Destroy(); override;
    class function GetType: TLBMPRequestType; override;
  published
    property ResultList: TPersistentList read fResultList write SetResultList;    
  end;

  TLBMPRESRegister = class(TLBMPResponsePackage)
  private
    fResultList: TPersistentList;
    procedure SetResultList(const Value: TPersistentList);
  public
    constructor Create(); override;
    destructor Destroy(); override;
    class function GetType: TLBMPRequestType; override;
  published
    property ResultList: TPersistentList read fResultList write SetResultList;    
  end;

  TLBMPRESUnRegister = class(TLBMPResponsePackage)
  private
    fResultList: TPersistentList;
    procedure SetResultList(const Value: TPersistentList);
  public
    constructor Create(); override;
    destructor Destroy(); override;
    class function GetType: TLBMPRequestType; override;
  published
    property ResultList: TPersistentList read fResultList write SetResultList;    
  end;

  TLBMPRESConfirmRegister = class(TLBMPResponsePackage)
  private
    fResultList: TPersistentList;
    procedure SetResultList(const Value: TPersistentList);
  public
    constructor Create(); override;
    destructor Destroy(); override;
    class function GetType: TLBMPRequestType; override;
  published
    property ResultList: TPersistentList read fResultList write SetResultList;    
  end;

  TLBMPRESGetServiceStatus = class(TLBMPResponsePackage)
  private
    fResultList: TPersistentList;
    procedure SetResultList(const Value: TPersistentList);
  public
    constructor Create(); override;
    destructor Destroy(); override;
    class function GetType: TLBMPRequestType; override;
  published
    property ResultList: TPersistentList read fResultList write SetResultList;    
  end;

const
  LBMPRequestPackageClass: array [TLBMPRequestType] of TLBMPRequestPackageClass =
    (TLBMPREQGetAreaCode, TLBMPREQGetCoord, TLBMPREQRegister,
    TLBMPREQUnRegister, TLBMPREQGetServiceStatus, TLBMPREQConfirmRegister);

  LBMPResponsePackageClass: array [TLBMPRequestType] of TLBMPResponsePackageClass =
    (TLBMPRESGetAreaCode, TLBMPRESGetCoord, TLBMPRESRegister,
    TLBMPRESUnRegister, TLBMPRESGetServiceStatus, TLBMPRESConfirmRegister);

implementation

{ TLBMPREQMobilePhone }

constructor TLBMPREQMobilePhone.Create();
begin
  inherited;
  fPhones := TStringList.Create();
end;

destructor TLBMPREQMobilePhone.Destroy();
begin
  if fPhones <> nil then fPhones.Free();
  inherited;
end;

procedure TLBMPREQMobilePhone.SetPhones(const Value: TStrings);
begin
  if Value = nil then fPhones.Clear
  else fPhones.Assign(Value);
end;

{ TLBMPREQGetAreaCode }

class function TLBMPREQGetAreaCode.GetType: TLBMPRequestType;
begin
  Result := lbmpGetAreaCode;
end;

{ TLBMPRESGetAreaCode }

constructor TLBMPRESGetAreaCode.Create;
begin
  inherited;
  fResultList := TPersistentList.Create(TLBMPAreaCodeResult);
end;

destructor TLBMPRESGetAreaCode.Destroy;
begin
  fResultList.Free;
  inherited;
end;

class function TLBMPRESGetAreaCode.GetType: TLBMPRequestType;
begin
  Result := lbmpGetAreaCode;
end;

procedure TLBMPRESGetAreaCode.SetResultList(const Value: TPersistentList);
begin
  fResultList.Assign(Value);
end;

{ TLBMPRESGetCoord }

constructor TLBMPRESGetCoord.Create;
begin
  inherited;
  fResultList := TPersistentList.Create(TLBMPCoordResult);
end;

destructor TLBMPRESGetCoord.Destroy;
begin
  ResultList.Free;
  inherited;
end;

class function TLBMPRESGetCoord.GetType: TLBMPRequestType;
begin
  Result := lbmpGetCoord;
end;

procedure TLBMPRESGetCoord.SetResultList(const Value: TPersistentList);
begin
  fResultList.Assign(Value);
end;

{ TLBMPREQGetCoord }

class function TLBMPREQGetCoord.GetType: TLBMPRequestType;
begin
  Result := lbmpGetCoord;
end;

{ TLBMPREQRegister }

class function TLBMPREQRegister.GetType: TLBMPRequestType;
begin
  Result := lbmpRegister;
end;

{ TLBMPREQUnRegister }

class function TLBMPREQUnRegister.GetType: TLBMPRequestType;
begin
  Result := lbmpUnRegister;
end;

{ TLBMPREQGetServiceStatus }

class function TLBMPREQGetServiceStatus.GetType: TLBMPRequestType;
begin
  Result := lbmpGetLBSState;
end;

{ TLBMPREQConfirmRegister }

class function TLBMPREQConfirmRegister.GetType: TLBMPRequestType;
begin
  Result := lbmpConfirmRegister;
end;

{ TLBMPRESRegister }

constructor TLBMPRESRegister.Create;
begin
  inherited;
  fResultList := TPersistentList.Create(TLBMPServiceStatusResult);
end;

destructor TLBMPRESRegister.Destroy;
begin
  fResultList.Free;
  inherited;
end;

class function TLBMPRESRegister.GetType: TLBMPRequestType;
begin
  Result := lbmpRegister;
end;

procedure TLBMPRESRegister.SetResultList(const Value: TPersistentList);
begin
  fResultList.Assign(Value);
end;

{ TLBMPRESUnRegister }

constructor TLBMPRESUnRegister.Create;
begin
  inherited;
  fResultList := TPersistentList.Create(TLBMPPhoneActionResult);
end;

destructor TLBMPRESUnRegister.Destroy;
begin
  fResultList.Free;
  inherited;
end;

class function TLBMPRESUnRegister.GetType: TLBMPRequestType;
begin
  Result := lbmpUnRegister;
end;

procedure TLBMPRESUnRegister.SetResultList(const Value: TPersistentList);
begin
  fResultList.Assign(Value);
end;

{ TLBMPRESConfirmRegister }

constructor TLBMPRESConfirmRegister.Create;
begin
  inherited;
  fResultList := TPersistentList.Create(TLBMPPhoneActionResult);
end;

destructor TLBMPRESConfirmRegister.Destroy;
begin
  fResultList.Free;
  inherited;
end;

class function TLBMPRESConfirmRegister.GetType: TLBMPRequestType;
begin
  Result := lbmpConfirmRegister;
end;

procedure TLBMPRESConfirmRegister.SetResultList(const Value: TPersistentList);
begin
  fResultList.Assign(Value);
end;

{ TLBMPRESGetServiceStatus }

constructor TLBMPRESGetServiceStatus.Create;
begin
  inherited;
  fResultList := TPersistentList.Create(TLBMPServiceStatusResult);
end;

destructor TLBMPRESGetServiceStatus.Destroy;
begin
  fResultList.Free;
  inherited;
end;

class function TLBMPRESGetServiceStatus.GetType: TLBMPRequestType;
begin
  Result := lbmpGetLBSState;
end;

procedure TLBMPRESGetServiceStatus.SetResultList(
  const Value: TPersistentList);
begin
  fResultList.Assign(Value);
end;

end.
